//
//  KYTreatWayViewController.m
//  kuaiyi
//
//  Created by 杨亮 on 16/3/16.
//  Copyright © 2016年 kuaiyi. All rights reserved.
//

#import "KYTreatWayViewController.h"
#import "KYTreatWayModel.h"

@interface KYTreatWayViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)NSArray *modelList;
@end
    static NSString *ID = @"TreatWay";
@implementation KYTreatWayViewController
-(NSArray *)modelList{
    if (!_modelList) {
        _modelList = [KYTreatWayModel getModel];
    }
    return _modelList;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
}
-(void)setUpUI{
    UITableView *tableView = [[UITableView alloc]init];
    self.view = tableView;
    tableView.dataSource = self;
    tableView.delegate = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
    KYTreatWayModel *model = self.modelList[indexPath.row];
    if ([self.selectedModel isEqualToString: model.treatWay]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.textLabel.text = model.treatWay;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    KYTreatWayModel *model = self.modelList[indexPath.row];
    self.selectedModel = model.treatWay;
    [tableView reloadData];
    [self.navigationController popViewControllerAnimated:YES];
    //用通知
    [[NSNotificationCenter defaultCenter]postNotificationName:@"didSelectTreatWay" object:nil userInfo:@{@"treatWayModel":model}];
}
@end
